<?php

class UserController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout()->setLayout('layout');
    }

    public function indexAction()
    {
    	$index = $this->view;
    	$this->view->setEscape('htmlentities');
    }

    public function loginAction()
    {
        // action body
    }

    public function mobileloginAction()
    {
		$this->view->islogged = false;
		
    	//catch username and password
    	
    	
    	$dmUser = new Application_Model_DbTable_Auth();
    	
		
		
		if(isset($username) && isset($password)){
			$username = $this->getRequest()->getParam("username");
    		$password = $this->getRequest()->getParam("password");
    		
    		$row = $dmUser->isPresent($username);
			
			if($row !=null){
			if($row[0]->password == $password){	
				//effettua il login rispondendo con la view corretta
				$this->view->islogged = true;
				$this->view->user_id = $row[0]->user_id;
			}
		}
		else
		{
			//restituisci la view di errore
			$this->view->islogged = false;
		}
		}
    	
    	

    }

    public function registerAction()
    {
        // action body
    }

    public function mobileregisterAction()
    {
        $username = $this->_request->getParams('username');
    	$password = $this->_request->getParams('password');
    	$name = $this->_request->getParams('name');
    	$surname = $this->_request->getParams('surname');
    	$interests = $this->_request->getParams('interests');
    	$email = $this->_request->getParams('email');
    	
    	
    	
    	
    }

    public function getcontentsidAction()
    {
    	
    }

    public function contentviewAction()
    {
    	$contentview = $this->view;
    	
    	$auth = Zend_Auth::getInstance();
		if($auth->hasIdentity()){
		
			$this->view->identity = $auth->getIdentity();
			$this->view->loggedUser = $auth->getIdentity();
			$username = $auth->getIdentity();
			if ($username != null){
					$db = Zend_Db::factory('Pdo_Mysql', array(
				    'host'             => 'localhost',
				    'username'         => 'vidalelu_epic',
				    'password'         => 'vidale509123',
				    'dbname'           => 'vidalelu_epic'
				));
				//seleziona tutti i contenuti
				$authAdapter = Zend_Auth::getInstance();
				
				//Zend_Debug::dump($db);
				//$sql = 'SELECT * FROM '. $username;
				$array = array();
				Zend_Debug::dump($authAdapter->getIdentity());
				
				$storage = $auth->getStorage();
				$array = $storage->read($authAdapter->getResultRowObject(array('username','password')));
				Zend_Debug::dump($array);
				//$data = $db->fetchAll($sql);
				
				//imposta la variabile per il paginator
				$contentview->contents = $data;  
				
			}
		
    	}
    }
    

}













